package com.wn26.shopczpro.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.wn26.shopczpro.entity.Goods;
import com.wn26.shopczpro.service.GoodsServiceImpl;
@WebServlet("/GoodsListServlet")
public class GoodsListServlet extends HttpServlet {
	
	public GoodsListServlet() {
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		GoodsServiceImpl gsi = new GoodsServiceImpl();
		try {
			List<Goods> goodsList = gsi.listgoodsService();
			JSONArray goodsArray = JSONArray.parseArray(JSON.toJSONString(goodsList));
			String content = goodsArray.toJSONString();
			resp.getWriter().write(content);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);;
	}
}
